/************************************************************
* Copyright (C), 2013, YiXun.
* 模块名    : Precedence DB Operator接口
* 实现功能  :
* 备注      :

* 修改记录  :
* 日 期             修改人              修改内容
  2013-10-15         blucelu              创建
***********************************************************/
#ifndef _ACCOUNT_DB_OPERATOR_H_
#define _ACCOUNT_DB_OPERATOR_H_

#include <string>
#include <stdint.h>
#include <bitset>
#include <iostream>

#include "app_platform/help_macros.h"
#include "app_platform/intf_service.h"
#include "c2cent/storage/mysqlstorage.h"

#include "erp/account/ddo/businessunitsfilterddo_account.h"
#include "erp/account/ddo/businessunitsddo_account.h"
#include "account_db_operator.h"

//using namespace c2cent::library::wtimeelf;

namespace erp
{
    namespace account
    {
        namespace db
        {
            class CAccountDBOperator
            {
            public:
            	CAccountDBOperator(){}
                ~CAccountDBOperator(){}

                static int InitDB(IUserDefineCntl* pCntl);

            public:
           	 /**
           	 *
           	 *   添加/修改来往单位；传入来往单位SysNo不为0时则进行修改，反之则进行添加；
           	 *
           	 */
            int32_t ModifyBusinessUnits(
           		 const CCntlInfo& rCntlInfo,
           		 const std::string& strMachineKey,
           		 const std::string& strSource,
           		 uint32_t dwSceneId,
           		 uint32_t dwOption,
           		 const erp::account::ddo::CBusinessUnitsDdo& oBusinessUnitsDdo,
           		 const std::string& strInReserve,
           		 std::string& strErrmsg,
           		 uint64_t& ddwSysNo,
           		 std::string& strOutReserve
           		);

           	 /**
           	 *
           	 *   删除来往单位（逻辑）
           	 *
           	 */
            int32_t DeleteBusinessUnits(
    				const CCntlInfo& rCntlInfo,
    				const std::string& strMachineKey,
    				const std::string& strSource,
    				uint32_t dwSceneId,
    				uint32_t dwOption,
    				uint64_t ddwBusinessUnitsSysNo,
    				const std::string& strInReserve,
    				std::string& strErrmsg,
    				std::string& strOutReserve
            		);

           	 /**
           	 *
           	 *   根据分支机构ID批量获取分支机构信息
           	 *
           	 */
            int32_t GetBusinessUnitsBySysNos(
           		 const CCntlInfo& rCntlInfo,
           		 const std::string& strMachineKey,
           		 const std::string& strSource,
           		 uint32_t dwSceneId,
           		 uint32_t dwOption,
           		 const std::set<uint64_t> & setBusinessUnitsSysNos,
           		 const std::string& strInReserve,
           		 std::string& strErrmsg,
           		 std::map<uint64_t,uint32_t> & mapErrorCode,
           		 std::map<uint64_t,std::string> & mapErrorMsg,
           		 std::map<uint64_t,erp::account::ddo::CBusinessUnitsDdo> & mapBusinessUnitsDdo,
           		 std::string& strOutReserve
           		);

           	 /**
           	 *
           	 *   根据过滤条件查询来往单位列表信息
           	 *
           	 */
            int32_t GetBusinessUnitsByFilter(
           		 const CCntlInfo& rCntlInfo,
           		 const std::string& strMachineKey,
           		 const std::string& strSource,
           		 uint32_t dwSceneId,
           		 uint32_t dwOption,
           		 const erp::account::ddo::CBusinessUnitsFilterDdo& oFilter,
           		 const std::string& strInReserve,
           		 std::string& strErrmsg,
           		 uint32_t& dwTotal,
           		 std::vector<erp::account::ddo::CBusinessUnitsDdo> & vecBusinessUnitsDdo,
           		 std::string& strOutReserve
           		);

            private:
                c2cent::storage::CMySqlStorage m_oStorage;

                /*
                inline static time_t StrToTime(std::string strTime)
                {
                    if (strTime.empty())
                    {
                        return 0;
                    }

                    struct tm tm_time;
                    strptime(strTime.c_str(), "%Y-%m-%d %H:%M:%S", &tm_time);
                    return mktime(&tm_time);
                }
                */
            };
        }
    }
}

#endif	//_ACCOUNT_DB_OPERATOR_H_
